export const getUser = (state) => state.user;
export const hasLogin = (state) => state.hasLogin;
export const getShoppingCart = (state) => state.shoppingCart;
export const getNum = (state) => {
    // 购物车商品总数量
    return state.shoppingCart.reduce((x, y) => {
        return x.num + y.num;
    })
}
export const getIsAllCheck = (state) {
    // 判断是否全选
    return state.shoppingCart.every(ele => !!ele.check)
}
export const getCheckGoods = (state) {
    // 获取勾选的商品信息
    // 用于确认订单页面
    return state.shoppingCart.filter(ele => !!ele.check)
}
export const getCheckNum = (state) {
    // 获取购物车勾选的商品数量
    let totalNum = 0;
    state.shoppingCart.forEach(ele => {
        if (ele.check) {
            totalNum += ele.num;
        }
    });
    return totalNum;

}
export const getTotalPrice = (state) {
    // 购物车勾选的商品总价格
    let totalPrice = 0;
    for (let i = 0; i < state.shoppingCart.length; i++) {
        const temp = state.shoppingCart[i];
        if (temp.check) {
            totalPrice += temp.price * temp.num;
        }
    }
    return totalPrice;
}